<?php
$cs = Yii::app()->getClientScript();
$cs->registerCSSFile(Yii::app()->request->baseUrl . '/css/mobile/booking_find_1.css');
$screen = Blyn::app()->getUIManager()->getCurrentScreen();
$wxControl = $screen->getChildControl('BUIWXControl_1');
?>
<?php
$prevStr = Yii::t('site', '<<');
$nextStr = Yii::t('site', '>>');
$totalRows = 0;
$totalpages = 0;
$rowsPerPage = 50;
if (isset($curPageNo))
    $pageNo = $curPageNo;
else
    $pageNo = 1;
if (!isset($availableList) || $availableList == NULL) {
    $availableList = array();
    if (isset($findText) && $findText != NULL) {
        $findText = $findText . ' bookingStartTime<=' . time() . ' bookingEndTime>=' . time();
        if (isset($findContext) && $findContext != NULL) {
            $findContext = unserialize($findContext);
        } else {
            $findContext = Blyn::app()->getUIManager()->getCurrentScreen()->getContextVariable('findContext');
        }

        if ($findContext == NULL) {
            $availableList = Blyn::app()->getActiveApp()->findByFindText($findText);
            $totalRows = Blyn::app()->getActiveApp()->findCountByFindText($findText);
        } else {
            $availableList = Blyn::app()->getActiveApp()->findByFindText($findText, $findContext);
            $totalRows = Blyn::app()->getActiveApp()->findCountByFindText($findText);
        }
        $totalpages = ceil($totalRows / $rowsPerPage);
    }
} else {
    $totalRows = Blyn::app()->getActiveApp()->findCountByFindText($findText);
    $totalpages = ceil($totalRows / $rowsPerPage);
}
?>
<?php
$data = array();
$data['htmlOptions'] = array('class' => 'btn btn-primary');
$findContext = array();
if (!isset($findContext) || !is_array($findContext))
    $findContext = array();
if (isset($findText))
    $findContext['findText'] = $findText;

Blyn::app()->getUIManager()->getCurrentScreen()->addContextVariable('findContext', $findContext);
?>
<meta name="viewport" content="initial-scale=1, width=device-width, maximum-scale=1, user-scalable=no">
<meta name="viewport" content="initial-scale=1.0,user-scalable=no,maximum-scale=1" media="(device-height: 568px)">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-touch-fullscreen" content="yes">
<meta name="full-screen" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no">
<link href="style/index.css" rel="stylesheet">
<body>
    <header class="navbar">
        <div class="nav-wrap-left">
            <a class="react back" href="javascript:history.back()"><i class="text-icon icon-back"></i></a>
        </div>
        <h1 class="nav-header"><?php echo $flagText; ?></h1>

        <?php
        $screen = Blyn::app()->getUIManager()->getCurrentScreen();
        $wxControl = $screen->getChildControl('BUIWXControl_1');
        $wxControl->renderView('booking_navigation', array());
        ?>
    </header>

    <div id="tips"></div>

    <div class="deal-container">
        <div id="deals" class="deals-list">
            <dl class="list list-in">
                <dd>
                    <dl class="list">
                        <?php
                        foreach ($availableList as $id => $bookingItem) {
                            $date = date('Y.n.j', $bookingItem->getItem('startTime')->value);
                            $startTime = date('G:i', $bookingItem->getItem('startTime')->value);
                            $endTime = date('G:i', $bookingItem->getItem('endTime')->value);
                            $price = $bookingItem->getItem('price')->value;
                            $region = $bookingItem->getItem('region')->value;
                            //获取省份下面的城市，如：巴南
//    $regionAlias = $bookingItem->getItem('regionAlias')->value;
//    var_dump($region1);
//    $city1 = $bookingItem->getItem('cityAlias')->value;
//    var_dump($city1);


                            $str = $bookingItem->getItem('courtName')->value;
                            $str = trim($str);
                            if (!empty($str)) {
                                $result = '';
                                for ($i = 0; $i < strlen($str); $i++) {
                                    if (is_numeric($str[$i])) {
                                        $result.=$str[$i];
                                    }
                                }
                            }
                            $bookdetail = new BWMessage($result);
                            $courtMedia = $bookdetail->getMediaManager()->getMedia('image');
                            $courtAddress = $bookdetail->getMediaManager()->getMedia('address')->getContent();
                            $courtImage = NULL;
                            if ($courtMedia instanceof BWMedia) {
                                $courtImage = $bookdetail->getMediaManager()->getMedia('image')->getContent();
                            }
                            ?>
                            <dd style="position: relative;">
                                <?php
                                //预订
                                $data = array(
                                    'bookingId' => $bookingItem->getId(),
                                );
                                if (isset($findText)) {
                                    $data['findText'] = $findText;
                                    $data['findContext'] = $findContext;
                                    $data['flagText'] = $flagText;
                                }

                                $detailUrl = $wxControl->getLinkUrl(array('name' => 'courtDetail', 'id' => 'showAddBooking_1'), $data);
                                ?>

                                <a href="<?php echo $detailUrl; ?>">
                                    <div class="react" style="padding-top: 10px;padding-bottom: 6px;">
                                        <div class="left_picture" style="float: left;width: 1.7rem;height: 1.7rem;margin-right: 5px;">
                                            <img src="<?php echo Yii::app()->request->baseUrl . $courtImage; ?>" width="100%" height="100%"/>
                                        </div>
                                        <span style="color:black;display: inline-block;margin-bottom: 6px;"><?php echo $bookingItem->getItem('courtDisplayName')->value; ?></span>
                                        <br/>
                                        <span class="time" style="display: inline-block;margin-bottom: 6px;color: #FDB338;">
                                            <i class="text-icon" style="font-family: inherit;"><span class="booking_date"><?php echo $date; ?></span>&nbsp;<?php echo $startTime; ?>-<?php echo $endTime; ?></i>
                                        </span>
                                        <br/>
                                        <span style="display: inline-block;margin-bottom: 6px;color: gray;font-size: 13px;">地点：<?php echo $courtAddress; ?></span>
                                        <br/>
                                        <span class="" style="display: inline-block;margin-bottom: 6px;">
                                            <strong style="color:#2BB2A3;font-size: .5rem;"><?php echo $price; ?></strong>
                                            <span>元</span>
                                        </span>
                                    </div>
                                </a>
                                <div class="right_btn" style="position:absolute;right:10px;bottom:10px;">
                                    <span class="line-right">
                                        <?php $wxControl->renderView('booking_add_toggleButton_1', $data); ?>
                                    </span>
                                </div>
                            </dd>
                        <?php } ?>
                    </dl>
                </dd>
            </dl>
            <?php if (count($availableList) == 0) { ?>           
                <dl style="margin-top: 0;">
                    <dd style="margin: 0;">
                        <?php $wxControl->renderView('none_list', array('message' => '亲，暂时还没有可预订的场地哟！')); ?>
                    </dd>
                </dl>
            <?php } else { ?>
                <div class="wrapper buy-wrapper">
                    <?php
                    echo $wxControl->getLink(
                            array(
                        'name' => '进入支付',
                        'id' => 'showPayBooking_1'), array('htmlOptions' => array('class' => "btn btn-strong btn-tip J_buy buy-btn btn-block btn-larger")));
                    ?>
                </div>
            <?php } ?>
        </div>

        <div class="shade hide"></div>
    </div>
    <footer>
        <div class="footer-copyright">
            <div class="hr"></div>
            <span class="footer-copyright-text">
                Copyright © 2014 billyn.net </span>
        </div>
    </footer>
</body></html>